package team.knowers.qzhserver.user.userData.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import team.knowers.qzhserver.user.user.entity.dao.UserDO;
import team.knowers.qzhserver.user.user.service.impl.UserServiceImpl;
import team.knowers.qzhserver.user.userData.entity.dao.UserDataDO;
import team.knowers.qzhserver.user.userData.entity.vo.UserDataDetailsVO;
import team.knowers.qzhserver.user.userData.mapper.UserDataMapper;
import team.knowers.qzhserver.user.userData.service.UserDataService;

import java.security.Principal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author xtg
 * @date 2024/2/15 18:24
 */
@Service
public class UserDataServiceImpl extends ServiceImpl<UserDataMapper, UserDataDO> implements UserDataService {
    @Autowired
    private UserDataMapper userDataMapper;
    @Autowired
    private UserServiceImpl userService;

    @Override
    public UserDataDetailsVO getUserData(String id) {
        return userDataMapper.getUserDataVO(id);
    }

    @Override
    public Map<String, Object> getUserOnline(Principal principal) {
        if (principal == null) {
            return null;
        }
        String username = principal.getName();
        UserDO user = userService.getUserByUsername(username);
        Map<String, Object> data = new HashMap<>();
        data.put("username", user.getUsername());
        return data;
    }


}
